package com.ftg.wymall.util;

import java.util.UUID;

/**
 * 常量提示信息,用以处理文件上传功能
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/11/16 上午10:48
 */
public class TipUtils {

    public static final String AVATAR_FILE_PATH_LOGIC = "/upload/avatar/";
    public static final String AVATAR_FILE_PATH = "/home/kangjx/Desktop" + AVATAR_FILE_PATH_LOGIC;
    public static final int AVATAR_FILE_SIZE = 1024 * 1024 * 3;
    public static final String AVATAR_FILE_SIZE_TIP = "头像文件大小不能超过3MB";
    public static final String AVATAR_FILE_TYPE_TIP = "头像文件类型不匹配";
    public static final String AVATAR_FILE_FAILURE = "头像上传失败！！！";

    public static final String RESULT_AVATAR_IP = "serverIp";
    public static final String RESULT_AVATAR_FILENAME = "newFileName";
    public static final String RESULT_AVATAR_PATH = "uploadPath";
    public static final String RESULT_AVATAR_URL = "url";
    public static final String RESULT_AVATAR_NAME = "mess";
    public static final String RESULT_AVATAR_FAIL_NAME = "errorMess";
    public static final String RESULT_SUCCESS_DEL = "文件删除成功";
    public static final String RESULT_NO_EXIST = "文件已不存在了！！";

    public static final String RESULT_OLD_FILE_NAME = "path";

    /**
     * 根据给定的IP地址和文件名生成完整的URL地址
     *
     * @param ip          服务器IP地址
     * @param newFileName 新的文件名
     * @return 生成的URL地址
     */
    public static String getUrl(String ip, String newFileName) {
        return new StringBuilder("http://").append(ip).append(AVATAR_FILE_PATH_LOGIC).append(newFileName).toString();
    }


    /**
     * 获取头像文件名
     *
     * @param extension 扩展名
     * @return 头像文件名
     */
    public static String getAvatarFileName(String extension) {
        String AVATAR_FILE_NAME = UUID.randomUUID().toString();
        return AVATAR_FILE_NAME + "." + extension;
    }


}
